package com.tjec.project.portal.controller;

import com.tjec.common.utils.poi.ExcelUtil;
import com.tjec.framework.aspectj.lang.annotation.Log;
import com.tjec.framework.aspectj.lang.enums.BusinessType;
import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.framework.web.page.TableDataInfo;
import com.tjec.project.portal.domain.BmsNotes;
import com.tjec.project.portal.service.IBmsNotesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 便签Controller
 *
 * @author liuxu
 * @date 2020-05-12
 */
@Api(value = "便签Controller", tags = {"便签接口"})
@RestController
@RequestMapping("/portal/notes")
public class BmsNotesController extends BaseController {
    @Autowired
    private IBmsNotesService bmsNotesService;

    /**
     * 查询便签列表
     */
    @ApiOperation("查询便签列表")
    @GetMapping("/list")
    public TableDataInfo list(BmsNotes bmsNotes) {
        startPage();
        List<BmsNotes> list = bmsNotesService.selectBmsNotesList(bmsNotes);
        return getDataTable(list);
    }

    /**
     * 获取关联项目列表
     */
    @ApiOperation("获取关联项目列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "guid", value = "项目guid", required = false, dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "userGuid", value = "用户guid", required = false, dataType = "String", paramType = "query")
    })

    @GetMapping(value = "/getProjectList")
    public AjaxResult getProjectList(String guid,String userGuid) {
        return AjaxResult.success(bmsNotesService.getProjectList(guid,userGuid));
    }

    /**
     * 获取关联业务列表
     */
    @ApiOperation("获取关联业务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectGuid", value = "项目guid", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "guid", value = "业务guid", required = false, dataType = "String", paramType = "query")
    })
    @GetMapping(value = "/getBusinessList")
    public AjaxResult getBusinessList(String projectGuid, String guid) {
        return AjaxResult.success(bmsNotesService.getBusinessList(projectGuid, guid));
    }

    /**
     * 获取关联干系人列表
     */
    @ApiOperation("获取关联干系人列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectGuid", value = "项目guid", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "guid", value = "干系人guid", required = false, dataType = "String", paramType = "query")
    })
    @GetMapping(value = "/getStakeholderList")
    public AjaxResult getStakeholderList(String projectGuid, String guid) {
        return AjaxResult.success(bmsNotesService.getStakeholderList(projectGuid, guid));
    }

    /**
     * 导出便签列表
     */
    @Log(title = "便签", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmsNotes bmsNotes) {
        List<BmsNotes> list = bmsNotesService.selectBmsNotesList(bmsNotes);
        ExcelUtil<BmsNotes> util = new ExcelUtil<BmsNotes>(BmsNotes.class);
        return util.exportExcel(list, "notes");
    }

    /**
     * 获取便签详细信息
     */
    @ApiOperation("获取便签详细信息")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid) {
        return AjaxResult.success(bmsNotesService.selectBmsNotesByGuid(guid));
    }

    /**
     * 新增便签
     */
    @ApiOperation("新增便签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectId", value = "关联项目", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "projectName", value = "项目名称", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "businessId", value = "关联业务", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "stakeholderId", value = "关联干系人,多个干系人用逗号隔开", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "content", value = "内容", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "attachmentGuids", value = "文件guids,多个文件用逗号隔开", required = false, dataType = "String", paramType = "form")
    })
    @Log(title = "便签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmsNotes bmsNotes) {
        return toAjax(bmsNotesService.insertBmsNotes(bmsNotes));
    }

    /**
     * 修改便签
     */
    @ApiOperation("修改便签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "guid", value = "便签guid", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "projectId", value = "关联项目", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "projectName", value = "项目名称", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "businessId", value = "关联业务", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "stakeholderId", value = "关联干系人,多个干系人用逗号隔开", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "content", value = "内容", required = true, dataType = "String", paramType = "form"),
            @ApiImplicitParam(name = "attachmentGuids", value = "文件guids,多个文件用逗号隔开", required = false, dataType = "String", paramType = "form")
    })
    @Log(title = "便签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsNotes bmsNotes) {
        return toAjax(bmsNotesService.updateBmsNotes(bmsNotes));
    }

    /**
     * 删除便签
     */
    @ApiOperation("删除便签")
    @Log(title = "便签", businessType = BusinessType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids) {
        return toAjax(bmsNotesService.deleteBmsNotesByGuids(guids));
    }
}
